<template>
    <div>
        <div class="tableHeader">
        <div class="tableHeaderTitle">招聘列表</div>
            <div class="tableHeaderMenu">
                <el-button-group>
                    <el-button icon="el-icon-refresh" @click="refreshData" size="mini"></el-button>
                </el-button-group>
            </div>
        </div>
        <el-table ref="multipleTable" :data="recruitmentData" tooltip-effect="dark" style="width: 100%">
            <el-table-column label="序号" type="index" width="80"></el-table-column>
            <el-table-column prop="cr_position" label="招聘职位"></el-table-column>
            <el-table-column prop="cr_describe" label="招聘描述"></el-table-column>
            <el-table-column label="上班方式">
                <template slot-scope="scope">
                    <span v-if="scope.row.cr_way == '0'">兼职</span>
                    <span v-if="scope.row.cr_way == '1'">全职</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="260">
                <template slot-scope="scope">
                    <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pagination.currentPage"
            :page-sizes="[20,50,100,200]"
            :page-size="pagination.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pagination.dataLength"
        ></el-pagination>
        </el-col>
    </div>
</template>

<script>
    import { mapState,mapMutations } from 'vuex'
    export default {
        //数据源
        data(){
            return {

            }
        },
        //初始化函数
        mounted() {
            this.initData()
        },
        //计算属性
        computed: {
            ...mapState({
                recruitmentData : state => state.RecruitmentListModule.recruitmentData,
                pagination : state => state.RecruitmentListModule.pagination
             })
        },
        //组件方法
        methods: {
            initData(){
                this.$myLoading.startLoading()
                this.$http.getHttp(
                    this.$API.cmsRecruitmentSearch + "/skip/" +this.pagination.skip+ "/limit/" +this.pagination.pageSize+ "/cr_is_delete/0/count/1",
                    rs => {
                        this.$store.commit('RecruitmentListModule/updateRecruitmentData',rs.data)
                        this.$store.commit('RecruitmentListModule/updatePaginationDataLength',parseInt(rs.count))
                        this.$myLoading.endLoading()
                    }
                )
            },
            refreshData(){
                this.initData()
            },
            handleEdit(index,item){

                this.$router.push({
                    path: "/editRecruitment",
                    query : {
                        cr_id : item.cr_id
                    }
                })
                
            },
            handleDelete(index,item){

                var params = {
                    delete_where : "cr_id",
                    cr_id        : item.cr_id,
                    cr_is_delete : 1
                }

                this.$myPop.confirmBox("确认操作","确定要删除该招聘信息吗？",()=>{
                    this.$myLoading.startLoading()
                    this.$http.postHttp(
                        this.$API.cmsRecruitmentDelete,
                        params,
                        rs => {
                            this.$myLoading.endLoading()
                            this.$myPop.SuccessMessage()
                            this.initData()
                        }
                    )
                })

            },
            handleSizeChange(page){
               this.pagination.pageSize = page;
               this.initData();
            },
            handleCurrentChange(page){
                this.pagination.skip        = (page-1) * this.pagination.pageSize;
                this.pagination.currentPage = page;
                this.initData();
                
            }
        }
    }
</script>

<style lang="stylus" scoped>
@import '~PUBLIC_CSS';
</style>